﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Oracle.DataAccess.Client;
namespace formCyclicalPatternTestGuide
{
    public partial class formCyclicalPatternTestGuide : Form
    {
        #region 声明成员变量
        private string serverName;
        private string ProjectNum;
        private string WorkerID;
        private string RoleNum;
        private string currentStatus;
        private string connString;
        #endregion

        #region 构造函数
        public formCyclicalPatternTestGuide(string server, string project,
            string userID, string rolenum, string status, string connstr)
        {
            InitializeComponent();
            serverName = server;
            ProjectNum = project;
            WorkerID = userID;
            RoleNum = rolenum;
            currentStatus = status;
            connString = connstr;
        }
        #endregion


        private void formCyclicalPatternTestGuide_Load(object sender, EventArgs e)
        {
            //初始化dtblProjectBasicInfm和dtblTestGuide
            initialFormInfm();
            this.reportViewer1.RefreshReport();

            this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("formCyclicalPatternTestGuide_ProjectBasicInfm", this.dtblProjectBasicInfm));
            this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("formCyclicalPatternTestGuide_TestGuide", this.dtblTestGuide));

            //设置报表rdlc文件的路径
            this.reportViewer1.LocalReport.ReportEmbeddedResource = "formCyclicalPatternTestGuide_TestGuide.TestGuide.rdlc";
            this.reportViewer1.LocalReport.ReportPath = System.AppDomain.CurrentDomain.BaseDirectory + @"Rdlc\TestGuide.rdlc";
            //设置报表输出名称
            // this.reportViewer1.LocalReport.DisplayName = this.lblProductFigure.Text + "_材料/零件清单";
            this.reportViewer1.RefreshReport();
            //设置报表浏览器和返回按钮可见
            this.reportViewer1.Visible = true;
            this.reportViewer1.BringToFront();
            this.btnExit.Visible = true;
            this.btnExit.BringToFront();

        }

        //从后台读取数据库中内容
        private bool initialFormInfm()
        {
            this.dtblProjectBasicInfm.Clear();
            this.dtblTestGuide.Clear();

            OracleConnection conn = new OracleConnection(connString);
            OracleCommand orclCmd = new OracleCommand("system.formCyclicalPatternTestGuide .get_initial_infm", conn);
            orclCmd.CommandType = CommandType.StoredProcedure;
            orclCmd.BindByName = true;
            OracleParameter[] parameter ={
                                           new OracleParameter ("para_project_num",ProjectNum ),
                                           new OracleParameter ("cur_project_infm",OracleDbType .RefCursor ),
                                           new OracleParameter ("cur_ctrl_plan_content",OracleDbType .RefCursor ),
                                          
                                       };
            parameter[0].Direction = ParameterDirection.Input;
            parameter[1].Direction = ParameterDirection.Output;
            parameter[2].Direction = ParameterDirection.Output;

            foreach (OracleParameter para in parameter)
            {
                orclCmd.Parameters.Add(para);
            }
            OracleDataAdapter da = new OracleDataAdapter(orclCmd);

            da.TableMappings.Add("Table", "dtblProjectBasicInfm");
            da.TableMappings.Add("Table1", "dtblTestGuide");


            try
            {
                if (da.Fill(this.dataSet1) > 0)
                {

                    this.dtblTestGuide.GetChanges();
                    return true;
                }
                else
                    return false;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("异常原因：" + ex.Message);
                return false;
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
